<?php
namespace app\log\controller;
use app\common\controller\Common;
use think\Request;
use think\Exception;
class RepairLog extends Common
{
	protected $model = null;
	protected $keyword_search = [];
	protected $afterActionList = [
        'addOperLog'  =>  ['only'=>'add,del'],
    ];

	public function _initialize(){
		parent::_initialize();
		$this->model = model('RepairLog');
	}
	/**
	 * 新增维修进度
	 */
	public function add()
	{
		if(Request()->isGet()){
			return $this->fetch();
		}
		if(Request()->isPost()){
			$data = Request()->param('');
			if(!isset($data['repair_id']) && $data['repair_id'] == ''){
				$this->error(config('status.ERROR_ONE'));
			}
			$status = model('repair/Repair')->where('repair_id',$data['repair_id'])->value('state');
			$this->log_id = $this->model->addLog($data['repair_id'], $data['goods_sn'], $status);
			$this->success(config('status.SUCCESS_ONE'));
		}
	}
	/**
	 * 删除维修进度
	 */
	public function del($ids = null)
	{
		if($ids == null){
			$this->error(config('status.ERROR_ONE'));
		}
		try{
			$this->log_id = $ids;
			$this->model->where('repair_log_id',$ids)->delete($ids);
			$this->success(config('status.SUCCESS_ONE'));
		}catch(Exception $e){
			$this->error(config('status.ERROR_ONE'));
		}
	}
}